use winapi::um::winuser::{RegisterHotKey, UnregisterHotKey};
use winapi::um::errhandlingapi::GetLastError;
use winapi::shared::minwindef::UINT;

pub struct HotkeyManager {
    hotkey_id: i32,
}

impl HotkeyManager {
    pub fn new(hotkey_id: i32) -> Self {
        Self { hotkey_id }
    }

    pub fn register_ctrl_space(&self) -> Result<(), String> {
        unsafe {
            let result = RegisterHotKey(
                std::ptr::null_mut(),
                self.hotkey_id,
                winapi::um::winuser::MOD_CONTROL as UINT,
                winapi::um::winuser::VK_SPACE as UINT,
            );

            if result == 0 {
                let error = GetLastError();
                Err(format!("注册热键失败，错误代码: {}", error))
            } else {
                Ok(())
            }
        }
    }

    pub fn unregister(&self) {
        unsafe {
            UnregisterHotKey(std::ptr::null_mut(), self.hotkey_id);
        }
    }

    pub fn get_hotkey_id(&self) -> i32 {
        self.hotkey_id
    }
} 